from Tkinter import *
root = Tk()
canvas_width = 300
canvas_height = 500

x=canvas_width/2
y=canvas_height/2

canvas_width =300
canvas_height =300

def qu():
    quit()

def drawd(p):
    draw()

def draw():
   global y
   global x
   #w.create_oval(y, y, y+50,y+50 ,fill="#476042")
   try:
      part = t.get(SEL_FIRST, SEL_LAST)
      part= part.replace("\n","").replace("\r","").strip()
   except:
      part= ""
      
   if part == "circle":
      w.create_oval(x, y, x+50,y+50)

   if part == "up":
      #print part
      y= y-5
      w.move(pen,0,-5)

   if part == "quit":
      quit()

   if part == "up":
      #print part
      y= y-5
      w.move(pen,0,-5)

   if part == "down":
      #print part
      y= y+5
      w.move(pen,0,5)

   if part == "left":
      #print part
      x = x-5
      w.move(pen,-5,0)

   if part == "right":
      #print part
      x = x+5
      w.move(pen,5,0)
   
####canvas#####   
w = Canvas(root, width=canvas_width,height=canvas_height)
####text area #######
t = Text(root,height=10,width=100)

button_c = Button(root,text="run",command = draw)
button_d = Button(root,text="quit",command = qu)
#b_clear = Button(root,text="clear",command = w.delete("all"))

scroll = Scrollbar(root, command = t.yview)
t.configure(yscrollcommand = scroll.set)
t.bind('<Control-t>', drawd)

#cursor###
pen= w.create_oval(x,y,x+10,y+10)


w.pack()
button_c.pack()
#b_clear.pack()
t.pack(side = LEFT,fill = BOTH,expand = True)
scroll.pack(side = RIGHT , fill = Y)


mainloop()

################################################################
##LICENSE: Creative Commons cc0 1.0(public domain)
##Credit : fcr 
################################################################